package com.hzcx.app.simplechat.ui.login.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.common.Common;
import com.hzcx.app.simplechat.model.LoginModel;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.model.SettingModel;
import com.hzcx.app.simplechat.ui.login.bean.DomainNameBean;
import com.hzcx.app.simplechat.ui.login.bean.LoginInfoBean;
import com.hzcx.app.simplechat.ui.login.bean.UserRegisterBean;
import com.hzcx.app.simplechat.ui.login.contract.ForgetPwdContract;
import com.hzcx.app.simplechat.ui.login.contract.LoginContract;
import com.hzcx.app.simplechat.ui.publicui.bean.ProtocolBean;

public class LoginPresenter extends BasePresenter<LoginContract.View> implements LoginContract.Presenter {

    /**
     * 阿里云一键登录
     *
     * @param context
     * @param accessToken
     * @param logindevice
     */
    @Override
    public void loginByAli(Context context, String accessToken, String logindevice) {
        LoginModel.loginByAli(context, accessToken, logindevice, new BaseDialogObserver<LoginInfoBean>(context) {
            @Override
            protected void onSuccess(LoginInfoBean data) {
                mView.loginSuccess(data, 1);
                mView.hideLoading();
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.hideLoading();
            }
        });
    }

    /**
     * 微信登录
     *
     * @param context
     * @param code
     * @param logindevice
     */
    @Override
    public void loginByWx(Context context, String code, String logindevice) {
        LoginModel.loginByWx(context, code, logindevice, new BaseObserver<LoginInfoBean>() {
            @Override
            protected void onSuccess(LoginInfoBean data) {
                mView.loginSuccess(data, 2);
            }
        });
    }

    /**
     * 通过阿里token绑定手机号
     *
     * @param context
     * @param token
     * @param accessToken
     */
    @Override
    public void bindPhoneByAli(Context context, String token, String accessToken) {
        LoginModel.bindPhoneByAli(context, token, accessToken, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.bindSuccess();
            }
        });
    }

    /**
     * 获取协议内容
     *
     * @param context
     * @param type
     */
    @Override
    public void getProtocol(Context context, String type) {
        PublicModel.getProtocolByType(context, type, new BaseDialogObserver<ProtocolBean>(context) {
            @Override
            protected void onSuccess(ProtocolBean data) {
                mView.protocolResult(data);
            }
        });
    }

    /**
     * 用户是否注册
     *
     * @param context
     * @param mobile
     * @param area_code
     * @param uniquely
     */
    @Override
    public void getUserIsRegister(Context context, String mobile, String area_code, String uniquely) {
        LoginModel.getUserIsRegister(context, mobile, area_code, uniquely, new BaseDialogObserver<UserRegisterBean>(context) {
            @Override
            protected void onSuccess(UserRegisterBean data) {
                mView.userIsRegister(data.getIs_register());
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
            }
        });
    }

    /**
     *  获取域名配置
     */
    @Override
    public void getDomainNameConfig(Context context) {
        PublicModel.getDomainNameConfig(context, Common.BASE_DOMAIN_NAME, 1, new BaseObserver<DomainNameBean>() {
            @Override
            protected void onSuccess(DomainNameBean data) {
                mView.domainNameResult(data);
            }
        });
    }

}
